package com.team.recruitment_management_system.controller;

import com.team.recruitment_management_system.pojo.dto.company.*;
import com.team.recruitment_management_system.pojo.vo.CompanyInfoVo;
import com.team.recruitment_management_system.security.OperationLogAnnotation;
import com.team.recruitment_management_system.service.BusinessInformationService;
import com.team.recruitment_management_system.service.CompanyService;
import com.team.recruitment_management_system.util.result.PageResult;
import com.team.recruitment_management_system.util.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/company")
@Tag(name = "公司模块")
public class CompanyController {
    @Autowired
    private CompanyService companyService;

    @Autowired
    private BusinessInformationService businessInformationService;

    @PostMapping("/one")
    @Operation(summary = "添加公司", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "公司模块", operType = "插入", operDesc = "添加公司")
    public Result<Integer> addCompany(@RequestBody @Validated AddCompanyDto addCompanyDto) {
        return companyService.addCompany(addCompanyDto);
    }

    @PutMapping("/one")
    @Operation(summary = "修改公司", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "公司模块", operType = "修改", operDesc = "修改公司")
    public Result<Void> changeCompany(@RequestBody @Validated ChangeCompanyDto changeCompanyDto) {
        return companyService.changeCompany(changeCompanyDto);
    }

    @DeleteMapping("/one/{id}")
    @Operation(summary = "删除公司", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "公司模块", operType = "删除", operDesc = "删除公司")
    public Result<Void> deleteCompany(@PathVariable int id) {
        return companyService.deleteCompany(id);
    }

    @GetMapping("/info/{id}")
    @Operation(summary = "根据ID获取公司详细信息")
    public Result<CompanyInfoVo> getCompanyInfoByID(@PathVariable int id) {
        return companyService.getCompanyInfoByID(id);
    }

    @GetMapping("/more")
    @Operation(summary = "获取公司信息分页")
    public PageResult<CompanyInfoVo> getCompanyPage(CompanyPageQuery companyPageQuery) {
        return companyService.getCompanyPage(companyPageQuery);
    }

    @GetMapping("/hot")
    @Operation(summary = "求职者获取热门公司")
    public Result<List<CompanyInfoVo>> getHotCompany(){
        return companyService.getHotCompany();
    }

    @PostMapping("/business")
    @OperationLogAnnotation(operModul = "公司模块", operType = "插入", operDesc = "添加工商信息")
    @Operation(summary = "添加工商信息", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Void> addBusinessInformation(@RequestBody AddBusinessInformationDto addBusinessInformationDto) {
        return businessInformationService.addBusinessInformation(addBusinessInformationDto);
    }

    @PutMapping("/business")
    @OperationLogAnnotation(operModul = "公司模块", operType = "修改", operDesc = "修改工商信息")
    @Operation(summary = "修改工商信息", security = {@SecurityRequirement(name = "Authorization")})
    public Result<Void> changeBusinessInformation(@RequestBody ChangeBusinessInformationDto changeBusinessInformationDto) {
        return businessInformationService.changeBusinessInformation(changeBusinessInformationDto);
    }

}
